package com.woniuxy.controller;

import com.github.pagehelper.PageInfo;
import com.woniuxy.entity.po.system.Log;
import com.woniuxy.service.LogService;
import com.woniuxy.service.QuartzService;
import com.woniuxy.util.PageParam;
import com.woniuxy.util.ResponseData;
import org.quartz.SchedulerException;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

/**
 * @BelongsProject: community
 * @BelongsPackage: com.woniuxy.controller
 * @Author: Quan
 * @Date: 2025/3/3 14:24
 */
@RestController
@RequestMapping("/log")
public class LogController {
	@Resource
	private LogService logService;

	@Resource
	private QuartzService quartzService;

	@PostMapping("/queryAll")
	public ResponseData<?> queryLogInfo(@RequestBody PageParam<Log> pageParam) {
		return logService.queryLogInfo(pageParam);
	}

	@GetMapping("/queryUsername")
	public ResponseData<?> queryUsername() {
		List<String> usernameList = logService.queryUsername();
		return new ResponseData(200, usernameList, "操作成功");
	}

	@GetMapping("/setRetainTime/{retainTime}")
	public ResponseData<?> setRetainTime(@PathVariable("retainTime") String retainTime) throws SchedulerException, IOException {
		quartzService.modifyJob(retainTime);
		return new ResponseData(200, null, "操作成功");
	}

	@GetMapping("/setRetention/{retention}")
	public ResponseData<?> setRetention(@PathVariable("retention") Integer retention) {
		Integer a = 1/0;
		return logService.setRetention(retention);
	}

	/**
	 * @Description: 设置日志的保留时间
	 * @Param: []
	 * @return: com.woniuxy.util.ResponseData<?>
	 * @Author: Quan
	 * @Date: 2025/4/7
	 */
	@GetMapping("/getRetention")
	public ResponseData<?> getRetention() {
		return logService.getRetention();
	}
}
